//
//  XQCache.swift
//  Spark Peso
//
//  Created by 小琦 on 2025/1/27.
//

import UIKit
import AdSupport

let KXQTrackingIDFAInfo = "KXQTrackingIDFAInfo"

let KXQSession = "KXQSession"

let kXQShowGuide = "kXQShowGuide"

let kXQCityData = "kXQCityData"

class XQCache: NSObject {
    
    static func saveIdfa(idfa : String) {
        UserDefaults.standard.set(idfa, forKey:KXQTrackingIDFAInfo)
    }
    
    static func getIdfa() -> String {
        guard let idfa = UserDefaults.standard.string(forKey: KXQTrackingIDFAInfo) else {
            let idfa = ASIdentifierManager.shared().advertisingIdentifier.uuidString
            return idfa
        }
        return idfa
    }
    
    static func saveSessionId(sessionId : String) {
        UserDefaults.standard.set(sessionId, forKey:KXQSession)
    }
    
    static func getSessionId() -> String {
        guard let sessionId = UserDefaults.standard.string(forKey: KXQSession) else {
            return ""
        }
        return sessionId
    }
    
    static func saveShowGuide(show : Bool) {
        UserDefaults.standard.set(show, forKey:kXQShowGuide)
    }
    
    static func getShowGuide() -> Bool {
        let show = UserDefaults.standard.bool(forKey: kXQShowGuide) 
        return show
    }
    
    static func saveCityData(jsString : String) {
        UserDefaults.standard.set(jsString, forKey:kXQCityData)
    }
    
    static func getCityData() -> String {
        guard let data = UserDefaults.standard.string(forKey: kXQCityData) else {
            return ""
        }
        return data
    }
    
}
